#!/usr/bin/python
#-*- coding: utf-8 -*-
from numpy import array
from OpenGL.arrays import vbo
from OpenGL.GL import *
from OpenGL.GLU import *
from GameConfigFile import *
from coherence.upnp.devices import control_point


class MarbleRun(object):
        
    def __init__(self, coordinates):        
        self._vbo = vbo.VBO(array(coordinates, 'f')) # nicht in die draw nur einmal machen
        self.len_of_marble_run = len(coordinates)
        self.coordinates = coordinates
        
    def draw(self):
        """Zeichnet sich selbst in den Origin"""
        # An richtige position bringen
        glPushMatrix()
        # VBO Strecken-Linie
        
        #Bahn erstellen
        glEnableClientState(GL_VERTEX_ARRAY)
        self._vbo.bind()
        glLineWidth(MARBLE_RUN_WIDTH)
        glVertexPointerf(self._vbo)        
        glDrawArrays(GL_LINE_STRIP,0, self.len_of_marble_run)
        self._vbo.unbind()
        glDisableClientState(GL_VERTEX_ARRAY)
        
        glPopMatrix()

        #Stützen erstellen
        for i in range(self.len_of_marble_run/CYLINDER_FREQUENZY):
            glPushMatrix()
            k = i*CYLINDER_FREQUENZY
            glTranslate(self.coordinates[k][0], self.coordinates[k][1],self.coordinates[k][2])
            glRotate(90, 1, 0, 0)
            gluCylinder(gluNewQuadric(), CYLINDER_RADIUS, CYLINDER_RADIUS,
                      CUBE_SIZE, CUBE_SIZE, CYLINDER_DETAIL, 1)
                        
            glPopMatrix()
        
        
    def __repr__(self):
        return 'Murmelbahnkoordinaten:', self.coordinates
    
    
if __name__ == '__main__':
    print "Main"
